package com.quanxiaoha.weblog.common.domain.dos;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author: 犬小哈
 * @url: www.quanxiaoha.com
 * @date: 2025-01-28 15:00
 * @description: 用户登录日志实体类
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("t_user_login_log")
public class UserLoginLogDO {

    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户名
     */
    private String username;

    /**
     * 登录方式：1：用户名密码 2：邮箱验证码 3：手机验证码
     */
    private Integer loginType;

    /**
     * 登录IP地址
     */
    private String ipAddress;

    /**
     * 用户代理
     */
    private String userAgent;

    /**
     * 登录时间
     */
    private LocalDateTime loginTime;

    /**
     * 是否成功：0：失败 1：成功
     */
    private Boolean success;

    /**
     * 失败原因
     */
    private String failReason;

    /**
     * 登录类型枚举
     */
    public enum LoginType {
        USERNAME_PASSWORD(1, "用户名密码"),
        EMAIL_CODE(2, "邮箱验证码"),
        PHONE_CODE(3, "手机验证码");

        private final int code;
        private final String description;

        LoginType(int code, String description) {
            this.code = code;
            this.description = description;
        }

        public int getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }
    }
}
